package com.stu.student_back_end.controller;

import com.stu.student_back_end.common.Result;
import com.stu.student_back_end.controller.dto.CountDTO;
import com.stu.student_back_end.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 前端首页的controller
 */

@RestController
public class IndexController {

    @Autowired
    private ITblAccountService accountService;

    @Autowired
    private ITblBuildingService buildingService;

    @Autowired
    private ITblStudentService studentService;

    @Autowired
    private ITblDormService dormService;

    @Autowired
    private ITblMoveAndOutService moveAndOutService;

    @Autowired
    private ITblNoHereService noHereService;

    @GetMapping("/count")
    public Result queryCount() {
        //定义一个数组来接收数据
        List<CountDTO> list = new ArrayList<>();
        list.add(accountService.queryAccountCount());
        list.add(buildingService.queryBuildingCount());
        list.add(studentService.queryStudentCount());
        list.add(moveAndOutService.queryMoveAndOutCount());
        list.add(noHereService.queryNoHereCount());
        CountDTO count = new CountDTO();
        count.setCounts(list);
        return Result.success(count);
    }

    @GetMapping("/buildDormCount")
    public Result queryBuildDorm() {
        return Result.success(dormService.queryBuildNameCount());
    }
}
